﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using DFGK_WMS.WebAPI.Tools;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.数字孪生
{
    /// <summary>
    /// agv信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TAgvmesgController : ControllerBase
    {
        public ITAgvmesgRepository TAgvmesgRepository { get; set; }
        
        public TAgvmesgController(ITAgvmesgRepository tAgvmesgRepository)
        {
            this.TAgvmesgRepository = tAgvmesgRepository;
        }
        /// <summary>
        /// agv设备信息添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddAgvmesg(TAgvmesg msg)
        {
            if (!TAgvmesgRepository.AddAgvmesg(msg))
            {
                return Ok(BaseResult.ReturnInfo(1, "agv设备信息添加失败", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            }
            return Ok(BaseResult.ReturnInfo(0, "", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
        }
        /// <summary>
        /// agv设备故障或者任务结束时上报
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AgvmesgAppear(AgvmesgDto dto)
        {
            var model = TAgvmesgRepository.GetAgvmesg(x => x.taskCode == dto.taskCode);
            model.StackerStatus = dto.StackerStatus;
            model.Coord = dto.Coord;
            model.IsRunning = dto.IsRunning;
            if (!TAgvmesgRepository.UpdateAgvmesg(model))
            {
                return Ok(BaseResult.ReturnInfo(1, "agv设备修改失败", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            }
            return Ok(BaseResult.ReturnInfo(0, "", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
        }

    }
}
